{extend name="common/base" /}
{block name='title'}编辑菜单 - 菜单管理{/block}

{block name="body"}
<article class="clearfix pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-menu-edit">
        <input name="id" type="hidden" value="{$data.id}">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>上级菜单：</label>
            <div class="form-controls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
                <select class="select" name="pid" size="1">
                    <option value="0">顶级菜单</option>
                    {foreach $list as $k=>$v}
                    <option {if $data.pid == $v.id}selected{/if} value="{$v.id}">{for start="0" end="$v.level"}--{/for}{$v.menu_name}</option>
                    {/foreach}
                </select>
                </span> </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>菜单名称：</label>
            <div class="form-controls col-xs-8 col-sm-4">
                <input type="text" class="input-text" autocomplete="off" value="{$data.menu_name}" placeholder="菜单名称" id="name" name="name">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>路由：</label>
            <div class="form-controls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
                <select class="select" name="auth_id" size="1">
                    {foreach $auths as $k=>$v}
                    <option {if $data.auth_id == $v.id}selected{/if} value="{$v.id}">{for start="0" end="$v.level"}--{/for}{$v.auth_name}</option>
                    {/foreach}
                </select>
                </span> </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>菜单图标：</label>
            <div class="form-controls col-xs-8 col-sm-9 skin-minimal">
                {foreach $icons as $k=>$v}
                <div class="radio-box">
                    <input {if $data.icon_id == $v.id}checked{/if} name="icon_id" type="radio" value="{$v.id}" >
                    <label for="sex-1"><i class="Hui-iconfont" >&{$v['icon']};</i></label>
                </div>
                {/foreach}

            </div>
        </div>
        

        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        /* 通过iCheck插件，美化checkbox */
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        /* 表单验证，提交 */
        $("#form-menu-edit").validate({
            rules:{
                pid:{
                    required:true,
                    digits:true
                },
                name:{
                    required:true,
                },
                auth_id:{
                    required:true,
                },
                icon_id:{
                    required:true,
                },
            },
            messages: {
              name: {
                required: "菜单名不能为空",
              },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var name = $("input[name='name']").val();
                var id = $("input[name='id']").val();
                var icon_id = $("input[name='icon_id']:checked").val();
                var pid = $("select[name='pid']").val();
                var auth_id = $("select[name='auth_id']").val();
                $.ajax({
                    type: 'post', // 提交方式 get/post
                    url: "{:url('menu/edit')}", // 需要提交的 url
                    data: {
                        'name': name,
                        'auth_id': auth_id,
                        'icon_id': icon_id,
                        'pid' : pid,
                        'id' : id
                        
                    },
                    dataType: 'json',
                    success: function(ret) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}
